import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../tools/tools.dart';

// 我的页面
class MinePage extends StatefulWidget {
  const MinePage({Key? key}) : super(key: key);

  @override
  MinePageState createState() => MinePageState();
}

class MinePageState extends State<MinePage> {
  List<Map<String, dynamic>> listOne = [
    {'title': '企业信息', 'icon': 0xe60b, 'iconColor': 0xff1677FF, 'url': ''},
    {'title': '部门与成员', 'icon': 0xe606, 'iconColor': 0xff23B538, 'url': ''},
    {'title': '企业资质', 'icon': 0xe634, 'iconColor': 0xff00B1FF, 'url': ''},
    {'title': '行政检查', 'icon': 0xe6cd, 'iconColor': 0xffE97042, 'url': ''},
  ];
  List<Map<String, dynamic>> listTwo = [
    {'title': '我的订单', 'icon': 0xe602, 'iconColor': 0xff1677FF, 'url': ''},
    {'title': '我的服务', 'icon': 0xe609, 'iconColor': 0xffE97042, 'url': ''},
    {'title': '我的智聘', 'icon': 0xe6cc, 'iconColor': 0xff00B1FF, 'url': ''},
    {'title': '我的智选', 'icon': 0xe6cb, 'iconColor': 0xffE97042, 'url': ''},
    {'title': '设置', 'icon': 0xe60c, 'iconColor': 0xffFF9A30, 'url': 'mineSet'},
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: SzColor.f4f4f4,
      appBar: buildAppBar(),
      body: Stack(
        children: [
          // 背景
          Positioned(
            child: Container(
              height: rpx(100),
              decoration: BoxDecoration(
                color: SzColor.primary,
                borderRadius: BorderRadius.only(
                  bottomLeft: Radius.circular(rpx(20)),
                  bottomRight: Radius.circular(rpx(20)),
                ),
              ),
            ),
          ),
          Positioned(
            child: Expanded(
              child: ListView(
                children: [
                  // 第一部分
                  buildBodyOne(),
                  // 列表一
                  Container(
                    decoration: BoxDecoration(
                      color: const Color(0xffFFFFFF),
                      borderRadius: BorderRadius.circular(
                        rpx(20),
                      ),
                    ),
                    margin: EdgeInsets.only(
                      left: rpx(24),
                      right: rpx(24),
                      bottom: rpx(24),
                    ),
                    child: Column(
                      children: listOne
                          .map((e) => buildItem(context, item: e))
                          .toList(),
                    ),
                  ),
                  // 列表二
                  Container(
                    decoration: BoxDecoration(
                      color: const Color(0xffFFFFFF),
                      borderRadius: BorderRadius.circular(
                        rpx(20),
                      ),
                    ),
                    margin: EdgeInsets.symmetric(horizontal: rpx(24)),
                    child: Column(
                      children: listTwo
                          .map((e) => buildItem(context, item: e))
                          .toList(),
                    ),
                  ),
                  SizedBox(
                    height: rpx(80),
                  )
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  // 第一部分
  Widget buildBodyOne() {
    return Container(
      decoration: BoxDecoration(
        color: const Color(0xffFFFFFF),
        borderRadius: BorderRadius.circular(
          rpx(20),
        ),
      ),
      margin: EdgeInsets.only(
        left: rpx(24),
        right: rpx(24),
        bottom: rpx(24),
      ),
      padding: EdgeInsets.symmetric(vertical: rpx(30), horizontal: rpx(24)),
      child: Row(
        children: [
          Container(
            clipBehavior: Clip.hardEdge,
            width: rpx(120),
            height: rpx(120),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(rpx(100)),
              border: Border.all(width: rpx(1), color: Colors.black38),
            ),
            child: Image.asset(
              'images/imgs/service-hasll-swiper.png',
              fit: BoxFit.cover,
            ),
          ),
          SizedBox(
            width: rpx(20),
          ),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    '啊开了个',
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      fontSize: setSp(34),
                    ),
                  ),
                  SizedBox(
                    width: rpx(20),
                  ),
                  Builder(
                    builder: (BuildContext context) {
                      return Container(
                          decoration: BoxDecoration(
                            border: Border.all(
                              width: rpx(2),
                              color: Colors.green,
                            ),
                            borderRadius: BorderRadius.circular(
                              rpx(30),
                            ),
                          ),
                          padding: EdgeInsets.symmetric(
                            horizontal: rpx(10),
                            vertical: rpx(1),
                          ),
                          child: Row(
                            children: [
                              Icon(
                                const IconData(0xe605,
                                    fontFamily: 'AliIcon',
                                    matchTextDirection: true),
                                color: Colors.green,
                                size: setSp(26),
                              ),
                              SizedBox(
                                width: rpx(6),
                              ),
                              Text(
                                '已实名',
                                style: TextStyle(
                                    color: Colors.green, fontSize: setSp(24)),
                              )
                            ],
                          ));
                    },
                  ),
                ],
              ),
              SizedBox(
                height: rpx(10),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  ConstrainedBox(
                    constraints: BoxConstraints(maxWidth: rpx(450)),
                    child: const Text(
                      '阿克汉噶开始干活打',
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(color: SzColor.primary),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.only(left: rpx(10)),
                    child: Icon(
                      AliIcon.qingxuanzeyoujiantou,
                      color: SzColor.primary,
                      size: rpx(20),
                    ),
                  )
                ],
              )
            ],
          )
        ],
      ),
    );
  }

// 头部
  AppBar buildAppBar() {
    return AppBar(
      backgroundColor: SzColor.primary,
      centerTitle: true,
      title: const Text(
        '我的',
        style: TextStyle(color: Colors.white),
      ),
      actions: [
        GestureDetector(
          onTap: () {
            FPrint('信息');
          },
          child: Stack(
            alignment: Alignment.center,
            children: [
              Container(
                alignment: Alignment.centerLeft,
                width: rpx(60),
                height: rpx(60),
                child: Icon(
                  const IconData(
                    0xe60a,
                    fontFamily: 'AliIcon',
                    matchTextDirection: true,
                  ),
                  color: Colors.white,
                  size: setSp(40),
                ),
              ),
              Positioned(
                top: rpx(0),
                right: rpx(0),
                child: Container(
                  decoration: BoxDecoration(
                    color: Colors.red[600],
                    borderRadius: BorderRadius.circular(
                      rpx(30),
                    ),
                  ),
                  alignment: Alignment.center,
                  padding: EdgeInsets.symmetric(
                    horizontal: rpx(5),
                    vertical: rpx(3),
                  ),
                  child: Text(
                    '560',
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: setSp(16),
                      fontWeight: FontWeight.w700,
                    ),
                  ),
                ),
              )
            ],
          ),
        ),

        // 扫码
        IconButton(
          onPressed: () {},
          icon: Icon(
            const IconData(0xe60d,
                fontFamily: 'AliIcon', matchTextDirection: true),
            color: Colors.white,
            size: setSp(40),
          ),
        ),
        SizedBox(
          width: rpx(10),
        )
      ],
    );
  }

  // 每一项
  /// {required Map<String, dynamic>} item 数据
  Widget buildItem(BuildContext context, {required Map<String, dynamic> item}) {
    return GestureDetector(
      onTap: () {
        if (item['url'].length > 0) {
          Get.toNamed('mineSet');
        } else {
          SzEasyLoading.showToast('${item['title']} 暂无开启');
        }
      },
      child: Container(
        decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(
              color: SzColor.f4f4f4,
              width: rpx(1),
            ),
          ),
        ),
        padding: EdgeInsets.symmetric(vertical: rpx(36)),
        margin: EdgeInsets.symmetric(horizontal: rpx(24)),
        child: Row(
          children: [
            Icon(
              IconData(
                item['icon'],
                fontFamily: 'AliIcon',
                matchTextDirection: true,
              ),
              color: Color(item['iconColor']),
              size: setSp(45),
            ),
            SizedBox(
              width: rpx(20),
            ),
            Text(item['title']),
            const Expanded(
              child: Text(''),
            ),
            Icon(
              AliIcon.qingxuanzeyoujiantou,
              color: const Color(0xffC8C8C8),
              size: setSp(34),
            )
          ],
        ),
      ),
    );
  }
}
